package sort;

import java.util.*;

/**
 * Created With IntelliJ IDEA.
 * Descriptions:
 * author: Mr.Du
 * Date: 2022/11/16
 * Time: 23:03
 */
public class Merge {
    
    public int[][] merge(int[][] nums) {
        Map<Integer,Integer> mp = new HashMap<>();
        for(int i = 0;i < nums.length;i++){
            mp.put(nums[i][0],nums[i][1]);
        }
        Map<Integer,Integer> mp1 = new HashMap<>();
        int kOld = -1;
        int vOld = -1;
        for(Map.Entry<Integer,Integer> e : mp.entrySet()){
            int key = e.getKey();
            int value = e.getValue();
            if(kOld == -1){
                mp1.put(key,value);
                kOld = key;
                vOld = value;
            }else{
                if(key > vOld){
                    mp1.put(key,value);
                    kOld = key;
                    vOld = value;
                }else{
                    if(value > vOld ){
                        mp1.put(kOld,value);
                        vOld = value;
                    }
                }
            }
        }
        int[][] arr = new int[mp1.size()][2];
        int i = 0;
        for(Map.Entry<Integer,Integer> e : mp1.entrySet()){
            arr[i][0] = e.getKey();
            arr[i++][1] = e.getValue();
        }
        return arr;
    }
    
}
